{extend name="base" /}
{block name="js"}
<script src="__JS__/laydate/laydate.js"></script>
{/block}
{block name="body"}
<div class="layui-body">
    <!--tab标签-->
    <div class="layui-tab layui-tab-brief">
        <ul class="layui-tab-title">
            <li class="layui-this">网站概览</li>
        </ul>
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
                <table class="layui-table">
                    <tr>
                        <td style="width: 400px;">网站域名</td>
                        <td>{$config.url}</td>
                    </tr>
                    <tr>
                        <td>网站目录</td>
                        <td>{$config.document_root}</td>
                    </tr>
                    <tr>
                        <td>服务器操作系统</td>
                        <td>{$config.server_os}</td>
                    </tr>
                    <tr>
                        <td>服务器端口</td>
                        <td>{$config.server_port}</td>
                    </tr>
                    <tr>
                        <td>服务器环境</td>
                        <td>{$config.server_soft}</td>
                    </tr>
                    <tr>
                        <td>PHP版本</td>
                        <td>{$config.php_version}</td>
                    </tr>
                    <tr>
                        <td>MySQL版本</td>
                        <td>{$config.mysql_version}</td>
                    </tr>
                    <tr>
                        <td>最大上传限制</td>
                        <td>{$config.max_upload_size}</td>
                    </tr>
                </table>
            </div>

            <div class="layui-form">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label style="width: 90px;" class="layui-form-label">客服欢迎语</label>
                        <div class="layui-input-inline" style="width: 310px;">
                            <input type="text" name="welcoming" value="{$Think.session.wechat_info.welcoming}" class="layui-input" placeholder="">
                        </div>
                        <button class="layui-btn layui-btn-normal" onclick="setWelcoming();">确认</button>
                    </div>
                </div>
            </div>

                <div class="layui-form">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label style="width: 90px;" class="layui-form-label">选择时间范围</label>
                            <div class="layui-input-inline" style="width: 310px;">
                                <input type="text" class="layui-input" id="chioceTime" placeholder=" - ">
                            </div>
                            <button class="layui-btn layui-btn-normal" onclick="getTime()">搜索</button>
                        </div>
                    </div>
                </div>

            <div style="padding: 20px;text-align: center;font-family: 黑体;border: 1px solid #ccc;border-radius: 15px;box-shadow:2px 2px 15px;">
                
                <table style="width: 100%;">
                    <tr style="font-size: 30px;color:#00CD00;">
                        <th style="width: calc(100%/5);padding-bottom: 20px;">历史总关注数</th>
                        <th style="width: calc(100%/5);padding-bottom: 20px;">取消关注数</th>
                        <th style="width: calc(100%/5);padding-bottom: 20px;">净增数(目前关注数)</th>
                        <th style="width: calc(100%/5);padding-bottom: 20px;">二次关注数</th>
                        <th style="width: calc(100%/5);padding-bottom: 20px;">秒取关数</th>
                    </tr>
                    <tr style="font-size: 25px;color: #666;font-weight: 700;">
                        <td id="subscount">{$count.total}</td>
                        <td id="un_subscount">{$count.un_subscount}</td>
                        <td id="growth">{$count.subscount}</td>
                        <td id="repeat_subscribe_count">{$count.repeat_subscribe_count}</td>
                        <td id="second_unsubscribe_count">{$count.second_unsubscribe_count}</td>
                    </tr>
                </table>
                
            </div>
            {if condition="session('admin_id') eq 1"}
            <div style="margin-top: 15px;">
                <!-- 同步公众号信息 -->
                <button onclick="snycPub();" class="layui-btn">同步公众号信息</button>
                <button onclick="snycFans();" class="layui-btn">同步公众号粉丝信息</button>
            </div>
            {/if}
        </div>
    </div>
</div>
{/block}
{block name="script"}
<script>
    function snycPub(){
        
        layer.confirm('确认操作?', {
        btn: ['确认', '取消'] //可以无限个按钮
            }, function(index, layero){
            //按钮【按钮一】的回调
                var index = layer.load(2);
                $.get('{:url("admin/sync/syncPubInfo")}',function(res){
                    layer.msg(res.msg);
                    location.reload();
                });
            }, function(index){
            //按钮【按钮二】的回调
        });
        
    }

    function snycFans(){
        layer.confirm('确认操作?', {
        btn: ['确认', '取消'] //可以无限个按钮
            }, function(index, layero){
            //按钮【按钮一】的回调
                var index = layer.load(2);
                $.get('{:url("admin/sync/queue")}',function(res){
                    layer.msg(res.msg);
                    location.reload();
                });
            }, function(index){
            //按钮【按钮二】的回调
        });
    }

    layui.use('laydate', function () {
        var laydate = layui.laydate;
        laydate.render({
            elem: '#chioceTime',
            type: 'datetime',
            range: true,
            done: function (value, date, endDate) {

            }
        });
        // console.log()
    })

    function setWelcoming(){
        var welcome = $('input[name=welcoming]').val();
        $.ajax({
            url:"/admin/index/updateWelcoming",
            type:"post",
            data:{welcoming : welcome},
            success : function(res){
                if(res.status == 1){
                    layer.msg('修改成功',{time:2000},function(){
                        window.location.reload();
                    });
                }else{
                    layer.msg('修改成功');
                }
            }
        });
    }

    
    function getTime(){
        var start = (new Date($("#chioceTime").val().substr(0,19))).getTime()/1000;
        var stop = (new Date($("#chioceTime").val().substr(22,19))).getTime()/1000;
        $.get('/admin/index/subtime',{start_time:start,end_time:stop},function(res){
            $('#subscount').html(res.total);
            $('#un_subscount').html(res.un_subscount);
            $('#growth').html(res.subscount);
            $('#repeat_subscribe_count').html(res.repeat_subscribe_count);
            $('#second_unsubscribe_count').html(res.second_unsubscribe_count);
        });
    }

</script>
{/block}